package com.wang.back.controller;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.common.pojo.BasePojoEnum;
import com.wang.common.pojo.BaseQuery;
import com.wang.common.util.ConstatFinalUtil;
import com.wang.common.web.controller.BaseController;
import com.wang.train.pojo.AtPlanUsers;
import com.wang.train.pojo.AtPlanUsersQuery;
import com.wang.train.pojo.AtPlanDesc;
import com.wang.train.pojo.AtPlanDescQuery;
import com.wang.train.pojo.AtAnsSel;
import com.wang.train.pojo.AtAnsSelQuery;
import com.wang.train.pojo.AtAsk;
import com.wang.train.pojo.AtAskEnum;
import com.wang.train.pojo.AtAskQuery;
import com.wang.train.pojo.AtCate;
import com.wang.train.pojo.AtCateEnum;
import com.wang.train.pojo.AtCateQuery;
import com.wang.train.pojo.AtConsult;
import com.wang.train.pojo.AtConsultQuery;
import com.wang.train.pojo.AtExamDesc;
import com.wang.train.pojo.AtExamDescQuery;
import com.wang.train.pojo.AtExamDetail;
import com.wang.train.pojo.AtExamDetailQuery;
import com.wang.train.pojo.AtOrgan;
import com.wang.train.pojo.AtOrganQuery;
import com.wang.train.pojo.AtVideoDoc;
import com.wang.train.pojo.AtVideoDocEnum;
import com.wang.train.pojo.AtVideoDocQuery;
import com.wang.train.service.AtAnsSelService;
import com.wang.train.service.AtAskService;
import com.wang.train.service.AtCateService;
import com.wang.train.service.AtConsultService;
import com.wang.train.service.AtExamDescService;
import com.wang.train.service.AtExamDetailService;
import com.wang.train.service.AtExamScoreDescService;
import com.wang.train.service.AtExamScoreDetailService;
import com.wang.train.service.AtOrganService;
import com.wang.train.service.AtPlanDescService;
import com.wang.train.service.AtPlanUsersService;
import com.wang.train.service.AtVideoDocService;
import com.wang.users.pojo.AtRbacAdmins;
import com.wang.users.pojo.AtUsersDesc;
import com.wang.users.pojo.AtUsersDescQuery;
import com.wang.users.service.AtUsersDescService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;

/**
 * 示例的Controller
 * @author ZjxMi
 */
@Controller
@RequestMapping("/back/train")
@Log4j2
public class TrainBackController extends BaseController {
    @Autowired
    private AtCateService cateService;
    @Autowired
    private AtOrganService organService;
    @Autowired
    private AtConsultService consultService;
    @Autowired
    private AtVideoDocService videoDocService;
    @Autowired
    private AtAskService askService;
    @Autowired
    private AtAnsSelService ansSelService;
    @Autowired
    private AtExamDescService examDescService;
    @Autowired
    private AtExamDetailService examDetailService;
    @Autowired
    private AtPlanDescService planDescService;
    @Autowired
    private AtPlanUsersService planUsersService;
    @Autowired
    private AtExamScoreDescService examScoreDescService;
    @Autowired
    private AtExamScoreDetailService examScoreDetailService;
    @Autowired
    private AtUsersDescService usersDescService;

    /**
     * 分类查询多条
     * @return
     */
    @RequestMapping("/cateList")
    public String cateList(AtCateQuery paramQuery, Model model){
        log.info("==分类列表==");
        /* 分页对象 */
        IPage<AtCate> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtCate> dataList = this.cateService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtCate());
        /* 查询数据 */
        return "back/train/cateList";
    }

    /**
     * 分类打开添加页面
     * @return
     */
    @RequestMapping("/cateInsert")
    public String cateInsert(AtCateQuery paramQuery, Model model){
        log.info("==分类添加==");
        AtCate entity = paramQuery.getEntity();
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        /* 查询数据 */
        return "back/train/cateInsert";
    }

    /**
     * 分类添加提交操作
     * @return
     */
    @RequestMapping("/cateInsertSubmit")
    @ResponseBody
    public String cateInsertSubmit(HttpServletRequest request, AtCateQuery paramQuery, Model model){
        log.info("==分类添加提交==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        AtCate entity = paramQuery.getEntity();
        entity.setCreateId(adminsSess.getId());
        entity.setUpdateId(adminsSess.getId());
        boolean dbFlag = this.cateService.save(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 分类打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/cateUpdate")
    public String cateUpdate(AtCateQuery paramQuery, Model model){
        log.info("==分类更新==");
        /* 根据id查询 */
        AtCate one = this.cateService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "back/train/cateUpdate";
        }
        /* 查询数据 */
        return "back/train/cateInfo";
    }

    /**
     * 分类更新提交操作
     * <pre>
     * 分类表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/cateUpdateSubmit")
    @ResponseBody
    public String cateUpdateSubmit(HttpServletRequest request,AtCateQuery paramQuery, Model model){
        log.info("==分类更新提交==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        AtCate entity = paramQuery.getEntity();
        entity.setUpdateId(adminsSess.getId());
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.cateService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 分类打开添加页面
     * @return
     */
    @RequestMapping("/cateBatch")
    @ResponseBody
    public String cateBatch(AtCateQuery paramQuery, Model model){
        log.info("==分类批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtCateQuery paramQueryTemp = new AtCateQuery();
                        AtCate entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtCate dataDbResult = this.cateService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.cateService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtCateQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.cateService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtCateQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.cateService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.cateService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 机构查询多条
     * @return
     */
    @RequestMapping("/organList")
    public String organList(AtOrganQuery paramQuery, Model model){
        log.info("==机构列表==");
        /* 分页对象 */
        IPage<AtOrgan> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtOrgan> dataList = this.organService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtOrgan());
        /* 查询分类数据 */
        AtCateQuery cateQuery = new AtCateQuery();
        AtCate cateEntity = cateQuery.getEntity();
        cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        cateEntity.setCateType(AtCateEnum.CATETYPE_JGLX.getCode());
        List<AtCate> cateJglxList = this.cateService.findList(null, cateQuery);
        model.addAttribute("cateJglxList", cateJglxList);
        /* 查询分类数据 */
        cateQuery = new AtCateQuery();
        cateEntity = cateQuery.getEntity();
        cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        cateEntity.setCateType(AtCateEnum.CATETYPE_PXZQ.getCode());
        List<AtCate> catePxzqList = this.cateService.findList(null, cateQuery);
        model.addAttribute("catePxzqList", catePxzqList);
        /* 查询数据 */
        return "back/train/organList";
    }

    /**
     * 机构打开添加页面
     * @return
     */
    @RequestMapping("/organInsert")
    public String organInsert(AtOrganQuery paramQuery, Model model){
        log.info("==机构添加==");
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, new AtOrgan());
        /* 查询分类数据 */
        AtCateQuery cateQuery = new AtCateQuery();
        AtCate cateEntity = cateQuery.getEntity();
        cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        cateEntity.setCateType(AtCateEnum.CATETYPE_JGLX.getCode());
        List<AtCate> cateJglxList = this.cateService.findList(null, cateQuery);
        model.addAttribute("cateJglxList", cateJglxList);
        /* 查询分类数据 */
        cateQuery = new AtCateQuery();
        cateEntity = cateQuery.getEntity();
        cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        cateEntity.setCateType(AtCateEnum.CATETYPE_PXZQ.getCode());
        List<AtCate> catePxzqList = this.cateService.findList(null, cateQuery);
        model.addAttribute("catePxzqList", catePxzqList);
        /* 查询数据 */
        return "back/train/organInsert";
    }

    /**
     * 机构添加提交操作
     * @return
     */
    @RequestMapping("/organInsertSubmit")
    @ResponseBody
    public String organInsertSubmit(AtOrganQuery paramQuery, Model model){
        log.info("==机构添加提交==");
        boolean dbFlag = this.organService.save(paramQuery.getEntity());
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 机构打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/organUpdate")
    public String organUpdate(AtOrganQuery paramQuery, Model model){
        log.info("==机构更新==");
        /* 根据id查询 */
        AtOrgan one = this.organService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询分类数据 */
            AtCateQuery cateQuery = new AtCateQuery();
            AtCate cateEntity = cateQuery.getEntity();
            cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            cateEntity.setCateType(AtCateEnum.CATETYPE_JGLX.getCode());
            List<AtCate> cateJglxList = this.cateService.findList(null, cateQuery);
            model.addAttribute("cateJglxList", cateJglxList);
            /* 查询分类数据 */
            cateQuery = new AtCateQuery();
            cateEntity = cateQuery.getEntity();
            cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            cateEntity.setCateType(AtCateEnum.CATETYPE_PXZQ.getCode());
            List<AtCate> catePxzqList = this.cateService.findList(null, cateQuery);
            model.addAttribute("catePxzqList", catePxzqList);
            /* 查询数据 */
            return "back/train/organUpdate";
        }
        /* 查询数据 */
        return "back/train/organInfo";
    }

    /**
     * 机构更新提交操作
     * <pre>
     * 机构表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/organUpdateSubmit")
    @ResponseBody
    public String organUpdateSubmit(AtOrganQuery paramQuery, Model model){
        log.info("==机构更新提交==");
        AtOrgan entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.organService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 机构打开添加页面
     * @return
     */
    @RequestMapping("/organBatch")
    @ResponseBody
    public String organBatch(AtOrganQuery paramQuery, Model model){
        log.info("==机构批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtOrganQuery paramQueryTemp = new AtOrganQuery();
                        AtOrgan entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtOrgan dataDbResult = this.organService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.organService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtOrganQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.organService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtOrganQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.organService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.organService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 咨询查询多条
     * @return
     */
    @RequestMapping("/consultList")
    public String consultList(HttpServletRequest request,AtConsultQuery paramQuery, Model model){
        log.info("==咨询列表==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        /* 分页对象 */
        IPage<AtConsult> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtConsult> dataList = this.consultService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtConsult());
        /* 查询所有组织 */
        AtOrganQuery organQuery = new AtOrganQuery();
        AtOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
        model.addAttribute("ogranList", ogranList);
        /* 查询数据 */
        return "back/train/consultList";
    }

    /**
     * 咨询打开添加页面
     * @return
     */
    @RequestMapping("/consultInsert")
    public String consultInsert(AtConsultQuery paramQuery, Model model){
        log.info("==咨询添加==");
        /* 查询所有组织 */
        AtOrganQuery organQuery = new AtOrganQuery();
        AtOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
        model.addAttribute("ogranList", ogranList);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, new AtConsult());
        /* 查询数据 */
        return "back/train/consultInsert";
    }

    /**
     * 咨询添加提交操作
     * @return
     */
    @RequestMapping("/consultInsertSubmit")
    @ResponseBody
    public String consultInsertSubmit(AtConsultQuery paramQuery, Model model){
        log.info("==咨询添加提交==");
        boolean dbFlag = this.consultService.save(paramQuery.getEntity());
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 咨询打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/consultUpdate")
    public String consultUpdate(AtConsultQuery paramQuery, Model model){
        log.info("==咨询更新==");
        /* 根据id查询 */
        AtConsult one = this.consultService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询所有组织 */
            AtOrganQuery organQuery = new AtOrganQuery();
            AtOrgan organEntity = organQuery.getEntity();
            organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
            model.addAttribute("ogranList", ogranList);
            /* 查询数据 */
            return "back/train/consultUpdate";
        }
        /* 查询数据 */
        return "back/train/consultInfo";
    }

    /**
     * 咨询更新提交操作
     * <pre>
     * 咨询表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/consultUpdateSubmit")
    @ResponseBody
    public String consultUpdateSubmit(AtConsultQuery paramQuery, Model model){
        log.info("==咨询更新提交==");
        AtConsult entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.consultService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 咨询打开添加页面
     * @return
     */
    @RequestMapping("/consultBatch")
    @ResponseBody
    public String consultBatch(AtConsultQuery paramQuery, Model model){
        log.info("==咨询批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtConsultQuery paramQueryTemp = new AtConsultQuery();
                        AtConsult entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtConsult dataDbResult = this.consultService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.consultService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtConsultQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.consultService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtConsultQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.consultService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.consultService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 视频文档查询多条
     * @return
     */
    @RequestMapping("/videoDocList")
    public String videoDocList(HttpServletRequest request,AtVideoDocQuery paramQuery, Model model){
        log.info("==视频文档列表==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        /* 分页对象 */
        IPage<AtVideoDoc> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtVideoDoc> dataList = this.videoDocService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtVideoDoc());

        /* 查询分类数据 */
        AtCateQuery cateQuery = new AtCateQuery();
        AtCate cateEntity = cateQuery.getEntity();
        cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        cateEntity.setCateType(AtCateEnum.CATETYPE_WDSPLX.getCode());
        List<AtCate> cateWdsplxList = this.cateService.findList(null, cateQuery);
        model.addAttribute("cateWdsplxList", cateWdsplxList);
        /* 查询所有组织 */
        AtOrganQuery organQuery = new AtOrganQuery();
        AtOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
        model.addAttribute("ogranList", ogranList);
        /* 查询数据 */
        return "back/train/videoDocList";
    }

    /**
     * 视频文档打开添加页面
     * @return
     */
    @RequestMapping("/videoDocInsert")
    public String videoDocInsert(AtVideoDocQuery paramQuery, Model model){
        log.info("==视频文档添加==");
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, new AtVideoDoc());
        /* 查询分类数据 */
        AtCateQuery cateQuery = new AtCateQuery();
        AtCate cateEntity = cateQuery.getEntity();
        cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        cateEntity.setCateType(AtCateEnum.CATETYPE_WDSPLX.getCode());
        List<AtCate> cateWdsplxList = this.cateService.findList(null, cateQuery);
        model.addAttribute("cateWdsplxList", cateWdsplxList);
        /* 查询所有组织 */
        AtOrganQuery organQuery = new AtOrganQuery();
        AtOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
        model.addAttribute("ogranList", ogranList);
        /* 查询数据 */
        return "back/train/videoDocInsert";
    }

    /**
     * 视频文档添加提交操作
     * @return
     */
    @RequestMapping("/videoDocInsertSubmit")
    @ResponseBody
    public String videoDocInsertSubmit(HttpServletRequest request,AtVideoDocQuery paramQuery, Model model){
        log.info("==视频文档添加提交==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        AtVideoDoc entity = paramQuery.getEntity();
        if (StringUtils.isEmpty(entity.getCreateId())) {
            entity.setCreateId(adminsSess.getId());
        }
        boolean dbFlag = this.videoDocService.save(paramQuery.getEntity());
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 视频文档打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/videoDocUpdate")
    public String videoDocUpdate(AtVideoDocQuery paramQuery, Model model){
        log.info("==视频文档更新==");
        /* 根据id查询 */
        AtVideoDoc one = this.videoDocService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询分类数据 */
            AtCateQuery cateQuery = new AtCateQuery();
            AtCate cateEntity = cateQuery.getEntity();
            cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            cateEntity.setCateType(AtCateEnum.CATETYPE_WDSPLX.getCode());
            List<AtCate> cateWdsplxList = this.cateService.findList(null, cateQuery);
            model.addAttribute("cateWdsplxList", cateWdsplxList);
            /* 查询所有组织 */
            AtOrganQuery organQuery = new AtOrganQuery();
            AtOrgan organEntity = organQuery.getEntity();
            organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
            model.addAttribute("ogranList", ogranList);
            /* 查询数据 */
            return "back/train/videoDocUpdate";
        } else if (BaseQuery.FINAL_OPER_UPDATE_Audit.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "back/train/videoDocAudit";
        }
        /* 查询数据 */
        return "back/train/videoDocInfo";
    }

    /**
     * 视频文档更新提交操作
     * <pre>
     * 视频文档表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/videoDocUpdateSubmit")
    @ResponseBody
    public String videoDocUpdateSubmit(HttpServletRequest request,AtVideoDocQuery paramQuery, Model model){
        log.info("==视频文档更新提交==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        AtVideoDoc entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        if (AtVideoDocEnum.STATUSNEW_SHTG.getCode().equalsIgnoreCase(entity.getStatus()) ||
                AtVideoDocEnum.STATUSNEW_SHBTG.getCode().equalsIgnoreCase(entity.getStatus())) {
            entity.setAuditId(adminsSess.getId());
            entity.setAuditTime(new Date());
        }
        boolean dbFlag = this.videoDocService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 视频文档打开添加页面
     * @return
     */
    @RequestMapping("/videoDocBatch")
    @ResponseBody
    public String videoDocBatch(AtVideoDocQuery paramQuery, Model model){
        log.info("==视频文档批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtVideoDocQuery paramQueryTemp = new AtVideoDocQuery();
                        AtVideoDoc entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtVideoDoc dataDbResult = this.videoDocService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.videoDocService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtVideoDocQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.videoDocService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtVideoDocQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.videoDocService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.videoDocService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 问题查询多条
     * @return
     */
    @RequestMapping("/askList")
    public String askList(AtAskQuery paramQuery, Model model){
        log.info("==问题列表==");
        /* 分页对象 */
        IPage<AtAsk> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtAsk> dataList = this.askService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtAsk());
        /* 查询数据 */
        return "back/train/askList";
    }

    /**
     * 问题打开添加页面
     * @return
     */
    @RequestMapping("/askInsert")
    public String askInsert(AtAskQuery paramQuery, Model model){
        log.info("==问题添加==");
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, new AtAsk());
        /* 查询数据 */
        return "back/train/askInsert";
    }

    /**
     * 问题添加提交操作
     * @return
     */
    @RequestMapping("/askInsertSubmit")
    @ResponseBody
    public String askInsertSubmit(HttpServletRequest request,AtAskQuery paramQuery, Model model){
        log.info("==问题添加提交==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        AtAsk entity = paramQuery.getEntity();
        entity.setCreateId(adminsSess.getId());
        boolean dbFlag = this.askService.save(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 问题打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/askUpdate")
    public String askUpdate(AtAskQuery paramQuery, Model model){
        log.info("==问题更新==");
        /* 根据id查询 */
        AtAsk one = this.askService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "back/train/askUpdate";
        } else if (BaseQuery.FINAL_OPER_UPDATE_Audit.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "back/train/askAudit";
        }
        /* 查询数据 */
        return "back/train/askInfo";
    }

    /**
     * 问题更新提交操作
     * <pre>
     * 问题表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/askUpdateSubmit")
    @ResponseBody
    public String askUpdateSubmit(HttpServletRequest request,AtAskQuery paramQuery, Model model){
        log.info("==问题更新提交==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        AtAsk entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        if (AtVideoDocEnum.STATUSNEW_SHTG.getCode().equalsIgnoreCase(entity.getStatus()) ||
                AtVideoDocEnum.STATUSNEW_SHBTG.getCode().equalsIgnoreCase(entity.getStatus())) {
            entity.setAuditId(adminsSess.getId());
            entity.setAuditTime(new Date());
        }
        boolean dbFlag = this.askService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 问题打开添加页面
     * @return
     */
    @RequestMapping("/askBatch")
    @ResponseBody
    public String askBatch(AtAskQuery paramQuery, Model model){
        log.info("==问题批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtAskQuery paramQueryTemp = new AtAskQuery();
                        AtAsk entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtAsk dataDbResult = this.askService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.askService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtAskQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.askService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtAskQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.askService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.askService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 答案查询多条
     * @return
     */
    @RequestMapping("/ansSelList")
    public String ansSelList(AtAnsSelQuery paramQuery, Model model){
        log.info("==答案列表==");
        /* 分页对象 */
        IPage<AtAnsSel> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtAnsSel> dataList = this.ansSelService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtAnsSel());
        /* 查询数据 */
        return "back/train/ansSelList";
    }

    /**
     * 答案打开添加页面
     * @return
     */
    @RequestMapping("/ansSelInsert")
    public String ansSelInsert(AtAnsSelQuery paramQuery, Model model){
        log.info("==答案添加==");
        AtAnsSel entity = paramQuery.getEntity();
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        /* 查询数据 */
        return "back/train/ansSelInsert";
    }

    /**
     * 答案添加提交操作
     * @return
     */
    @RequestMapping("/ansSelInsertSubmit")
    @ResponseBody
    public String ansSelInsertSubmit(AtAnsSelQuery paramQuery, Model model){
        log.info("==答案添加提交==");
        boolean dbFlag = this.ansSelService.save(paramQuery.getEntity());
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 答案打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/ansSelUpdate")
    public String ansSelUpdate(AtAnsSelQuery paramQuery, Model model){
        log.info("==答案更新==");
        /* 根据id查询 */
        AtAnsSel one = this.ansSelService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "back/train/ansSelUpdate";
        }
        /* 查询数据 */
        return "back/train/ansSelInfo";
    }

    /**
     * 答案更新提交操作
     * <pre>
     * 答案表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/ansSelUpdateSubmit")
    @ResponseBody
    public String ansSelUpdateSubmit(AtAnsSelQuery paramQuery, Model model){
        log.info("==答案更新提交==");
        AtAnsSel entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.ansSelService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 答案打开添加页面
     * @return
     */
    @RequestMapping("/ansSelBatch")
    @ResponseBody
    public String ansSelBatch(AtAnsSelQuery paramQuery, Model model){
        log.info("==答案批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtAnsSelQuery paramQueryTemp = new AtAnsSelQuery();
                        AtAnsSel entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtAnsSel dataDbResult = this.ansSelService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.ansSelService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtAnsSelQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.ansSelService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtAnsSelQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.ansSelService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.ansSelService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 试卷概要查询多条
     * @return
     */
    @RequestMapping("/examDescList")
    public String examDescList(AtExamDescQuery paramQuery, Model model){
        log.info("==试卷概要列表==");
        /* 分页对象 */
        IPage<AtExamDesc> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtExamDesc> dataList = this.examDescService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtExamDesc());

        /* 查询所有组织 */
        AtOrganQuery organQuery = new AtOrganQuery();
        AtOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
        model.addAttribute("ogranList", ogranList);
        /* 查询数据 */
        return "back/train/examDescList";
    }

    /**
     * 试卷概要打开添加页面
     * @return
     */
    @RequestMapping("/examDescInsert")
    public String examDescInsert(AtExamDescQuery paramQuery, Model model){
        log.info("==试卷概要添加==");
        AtExamDesc entity = paramQuery.getEntity();
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);
        /* 查询所有组织 */
        AtOrganQuery organQuery = new AtOrganQuery();
        AtOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
        model.addAttribute("ogranList", ogranList);
        /* 查询数据 */
        return "back/train/examDescInsert";
    }

    /**
     * 试卷概要添加提交操作
     * @return
     */
    @RequestMapping("/examDescInsertSubmit")
    @ResponseBody
    public String examDescInsertSubmit(HttpServletRequest request,AtExamDescQuery paramQuery, Model model){
        log.info("==试卷概要添加提交==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        AtExamDesc entity = paramQuery.getEntity();
        if (StringUtils.isEmpty(entity.getCreateId())) {
            entity.setCreateId(adminsSess.getId());
        }
        if (StringUtils.isNotEmpty(paramQuery.getStTime())) {
            entity.setStTime(this.dateUtil.strToDateTime(paramQuery.getStTime()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdTime())) {
            entity.setEdTime(this.dateUtil.strToDateTime(paramQuery.getEdTime()));
        }
        boolean dbFlag = this.examDescService.save(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 试卷概要打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/examDescUpdate")
    public String examDescUpdate(AtExamDescQuery paramQuery, Model model){
        log.info("==试卷概要更新==");
        /* 根据id查询 */
        AtExamDesc one = this.examDescService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询所有组织 */
            AtOrganQuery organQuery = new AtOrganQuery();
            AtOrgan organEntity = organQuery.getEntity();
            organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
            model.addAttribute("ogranList", ogranList);
            /* 查询数据 */
            return "back/train/examDescUpdate";
        }
        /* 查询数据 */
        return "back/train/examDescInfo";
    }

    /**
     * 试卷概要更新提交操作
     * <pre>
     * 试卷概要表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/examDescUpdateSubmit")
    @ResponseBody
    public String examDescUpdateSubmit(AtExamDescQuery paramQuery, Model model){
        log.info("==试卷概要更新提交==");
        AtExamDesc entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getStTime())) {
            entity.setStTime(this.dateUtil.strToDateTime(paramQuery.getStTime()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdTime())) {
            entity.setEdTime(this.dateUtil.strToDateTime(paramQuery.getEdTime()));
        }
        boolean dbFlag = this.examDescService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 试卷概要打开添加页面
     * @return
     */
    @RequestMapping("/examDescBatch")
    @ResponseBody
    public String examDescBatch(AtExamDescQuery paramQuery, Model model){
        log.info("==试卷概要批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtExamDescQuery paramQueryTemp = new AtExamDescQuery();
                        AtExamDesc entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtExamDesc dataDbResult = this.examDescService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.examDescService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtExamDescQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.examDescService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtExamDescQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.examDescService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.examDescService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 试卷明细查询多条
     * @return
     */
    @RequestMapping("/examDetailList")
    public String examDetailList(AtExamDetailQuery paramQuery, Model model){
        log.info("==试卷明细列表==");
        /* 分页对象 */
        IPage<AtExamDetail> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtExamDetail> dataList = this.examDetailService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtExamDetail());
        /* 查询数据 */
        return "back/train/examDetailList";
    }

    /**
     * 试卷明细打开添加页面
     * <pre>
     *     思路:
     *     根据试卷id查询试卷信息
     *     根据试卷的分类,随机查询题库列表,显示到页面中
     * </pre>
     * @return
     */
    @RequestMapping("/examDetailInsert")
    public String examDetailInsert(AtExamDetailQuery paramQuery, Model model){
        log.info("==试卷明细添加==");
        AtExamDetail entity = paramQuery.getEntity();
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);

        /* 查询试卷信息 */
        AtExamDescQuery examDescQuery = new AtExamDescQuery();
        AtExamDesc examDescEntity = examDescQuery.getEntity();
        examDescEntity.setId(entity.getExamId());
        AtExamDesc examDescDb = this.examDescService.findOne(examDescQuery);
        /* 试卷明细集合 */
        List<AtExamDetail> examDetailList = Lists.newArrayList();
        if (Objects.nonNull(examDescDb)) {
            /* 删除之前的所有数据 */
            AtExamDetailQuery detailQuery = new AtExamDetailQuery();
            AtExamDetail detailEntity = detailQuery.getEntity();
            detailEntity.setExamId(entity.getExamId());
            this.examDetailService.deleteBatch(paramQuery);
            /* 试卷总分 */
            int totalScore = examDescDb.getScore();

            int currSCore = 0;
            outer:while(true) {
                /* 随机生成条数 */
                Random random = new Random();
                int randInt = random.nextInt(20);
                AtAskQuery askQuery = new AtAskQuery();
                AtAsk askEntity = askQuery.getEntity();
                askEntity.setStatus(AtAskEnum.STATUSNEW_SHTG.getCode());
                askEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                askQuery.setOrderBy("pubTimeAsc");
                IPage<AtAsk> askPage = new Page<>(1, randInt);
                List<AtAsk> askList = this.askService.findList(askPage, askQuery);
                inner:for (AtAsk dataTemp : askList) {
                    currSCore += dataTemp.getScore();
                    if (currSCore > totalScore) {
                        break outer;
                    }

                    AtExamDetail examDetail = new AtExamDetail();
                    examDetail.setId(IdWorker.getIdStr());
                    examDetail.setAskId(dataTemp.getId());
                    examDetail.setExamId(entity.getExamId());
                    examDetail.setScore(dataTemp.getScore());
                    examDetail.setHardStar(dataTemp.getHardStar());
                    examDetail.setAskType(dataTemp.getAskType());
                    examDetail.setName(dataTemp.getName());
                    examDetail.setContent(dataTemp.getContent());
                    examDetailList.add(examDetail);
                    this.examDetailService.save(examDetail);

                    dataTemp.setPubTime(new Date());
                    boolean dbFlag = this.askService.updateById(dataTemp);
                    log.info("==更新试题状态:{}==", dbFlag);
                }
            }
        }
        model.addAttribute("examDetailList", examDetailList);
        /* 查询数据 */
        return "back/train/examDetailInsert";
    }

    /**
     * 试卷明细添加提交操作
     * @return
     */
    @RequestMapping("/examDetailInsertSubmit")
    @ResponseBody
    public String examDetailInsertSubmit(AtExamDetail[] detailArr, Model model){
        log.info("==试卷明细添加提交==");
        boolean dbFlag = true;
        for (AtExamDetail dataTemp : detailArr) {
            dbFlag = this.examDetailService.save(dataTemp);
        }
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 试卷明细打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/examDetailUpdate")
    public String examDetailUpdate(AtExamDetailQuery paramQuery, Model model){
        log.info("==试卷明细更新==");
        /* 根据id查询 */
        AtExamDetail one = this.examDetailService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "back/train/examDetailUpdate";
        }
        /* 查询数据 */
        return "back/train/examDetailInfo";
    }

    /**
     * 试卷明细更新提交操作
     * <pre>
     * 试卷明细表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/examDetailUpdateSubmit")
    @ResponseBody
    public String examDetailUpdateSubmit(AtExamDetailQuery paramQuery, Model model){
        log.info("==试卷明细更新提交==");
        AtExamDetail entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.examDetailService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 试卷明细打开添加页面
     * @return
     */
    @RequestMapping("/examDetailBatch")
    @ResponseBody
    public String examDetailBatch(AtExamDetailQuery paramQuery, Model model){
        log.info("==试卷明细批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtExamDetailQuery paramQueryTemp = new AtExamDetailQuery();
                        AtExamDetail entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtExamDetail dataDbResult = this.examDetailService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.examDetailService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtExamDetailQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.examDetailService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtExamDetailQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.examDetailService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.examDetailService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 培训计划查询多条
     * @return
     */
    @RequestMapping("/planDescList")
    public String planDescList(AtPlanDescQuery paramQuery, Model model){
        log.info("==培训计划列表==");
        /* 分页对象 */
        IPage<AtPlanDesc> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtPlanDesc> dataList = this.planDescService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtPlanDesc());

        /* 查询分类数据 */
        AtCateQuery cateQuery = new AtCateQuery();
        AtCate cateEntity = cateQuery.getEntity();
        cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        cateEntity.setCateType(AtCateEnum.CATETYPE_PXLX.getCode());
        List<AtCate> catePxlxList = this.cateService.findList(null, cateQuery);
        model.addAttribute("catePxlxList", catePxlxList);
        /* 查询所有组织 */
        AtOrganQuery organQuery = new AtOrganQuery();
        AtOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
        model.addAttribute("ogranList", ogranList);
        /* 查询数据 */
        return "back/train/planDescList";
    }

    /**
     * 培训计划打开添加页面
     * @return
     */
    @RequestMapping("/planDescInsert")
    public String planDescInsert(HttpServletRequest request,AtPlanDescQuery paramQuery, Model model){
        log.info("==培训计划添加==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        
        AtPlanDesc entity = paramQuery.getEntity();
        /* 查询分类数据 */
        AtCateQuery cateQuery = new AtCateQuery();
        AtCate cateEntity = cateQuery.getEntity();
        cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        cateEntity.setCateType(AtCateEnum.CATETYPE_PXLX.getCode());
        List<AtCate> catePxlxList = this.cateService.findList(null, cateQuery);
        model.addAttribute("catePxlxList", catePxlxList);
        /* 查询所有组织 */
        AtOrganQuery organQuery = new AtOrganQuery();
        AtOrgan organEntity = organQuery.getEntity();
        organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
        model.addAttribute("ogranList", ogranList);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, entity);
        /* 查询当前机构的考试和视频 */
        AtExamDescQuery examDescQuery = new AtExamDescQuery();
        AtExamDesc examDescEntity = examDescQuery.getEntity();
        examDescEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        examDescEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        examDescEntity.setOrganId(adminsSess.getOrganId());
        List<AtExamDesc> examDescList = this.examDescService.findList(null, examDescQuery);
        model.addAttribute("examDescList", examDescList);

        AtVideoDocQuery videoDocQuery = new AtVideoDocQuery();
        AtVideoDoc videoDocEntity = videoDocQuery.getEntity();
        videoDocEntity.setStatus(AtVideoDocEnum.STATUSNEW_SHTG.getCode());
        videoDocEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
        videoDocEntity.setOrganId(adminsSess.getOrganId());
        List<AtVideoDoc> videoDocList = this.videoDocService.findList(null, videoDocQuery);
        model.addAttribute("videoDocList", videoDocList);
        /* 查询数据 */
        return "back/train/planDescInsert";
    }

    /**
     * 培训计划添加提交操作
     * @return
     */
    @RequestMapping("/planDescInsertSubmit")
    @ResponseBody
    public String planDescInsertSubmit(AtPlanDescQuery paramQuery, Model model){
        log.info("==培训计划添加提交==");
        boolean dbFlag = this.planDescService.save(paramQuery.getEntity());
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 培训计划打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/planDescUpdate")
    public String planDescUpdate(HttpServletRequest request,AtPlanDescQuery paramQuery, Model model){
        log.info("==培训计划更新==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        /* 根据id查询 */
        AtPlanDesc one = this.planDescService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询分类数据 */
            AtCateQuery cateQuery = new AtCateQuery();
            AtCate cateEntity = cateQuery.getEntity();
            cateEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            cateEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            cateEntity.setCateType(AtCateEnum.CATETYPE_PXLX.getCode());
            List<AtCate> catePxlxList = this.cateService.findList(null, cateQuery);
            model.addAttribute("catePxlxList", catePxlxList);
            /* 查询所有组织 */
            AtOrganQuery organQuery = new AtOrganQuery();
            AtOrgan organEntity = organQuery.getEntity();
            organEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            organEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            List<AtOrgan> ogranList = this.organService.findList(null, organQuery);
            model.addAttribute("ogranList", ogranList);

            /* 查询当前机构的考试和视频 */
            AtExamDescQuery examDescQuery = new AtExamDescQuery();
            AtExamDesc examDescEntity = examDescQuery.getEntity();
            examDescEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
            examDescEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            examDescEntity.setOrganId(adminsSess.getOrganId());
            List<AtExamDesc> examDescList = this.examDescService.findList(null, examDescQuery);
            model.addAttribute("examDescList", examDescList);

            AtVideoDocQuery videoDocQuery = new AtVideoDocQuery();
            AtVideoDoc videoDocEntity = videoDocQuery.getEntity();
            videoDocEntity.setStatus(AtVideoDocEnum.STATUSNEW_SHTG.getCode());
            videoDocEntity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
            videoDocEntity.setOrganId(adminsSess.getOrganId());
            List<AtVideoDoc> videoDocList = this.videoDocService.findList(null, videoDocQuery);
            model.addAttribute("videoDocList", videoDocList);
            /* 查询数据 */
            return "back/train/planDescUpdate";
        }
        /* 查询数据 */
        return "back/train/planDescInfo";
    }

    /**
     * 培训计划更新提交操作
     * <pre>
     * 培训计划表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/planDescUpdateSubmit")
    @ResponseBody
    public String planDescUpdateSubmit(AtPlanDescQuery paramQuery, Model model){
        log.info("==培训计划更新提交==");
        AtPlanDesc entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.planDescService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 培训计划打开添加页面
     * @return
     */
    @RequestMapping("/planDescBatch")
    @ResponseBody
    public String planDescBatch(AtPlanDescQuery paramQuery, Model model){
        log.info("==培训计划批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtPlanDescQuery paramQueryTemp = new AtPlanDescQuery();
                        AtPlanDesc entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtPlanDesc dataDbResult = this.planDescService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.planDescService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtPlanDescQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.planDescService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtPlanDescQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.planDescService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.planDescService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 培训用户查询多条
     * @return
     */
    @RequestMapping("/planUsersList")
    public String planUsersList(AtPlanUsersQuery paramQuery, Model model){
        log.info("==培训用户列表==");
        /* 分页对象 */
        IPage<AtPlanUsers> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtPlanUsers> dataList = this.planUsersService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtPlanUsers());
        /* 查询数据 */
        return "back/train/planUsersList";
    }

    /**
     * 培训用户打开添加页面
     * @return
     */
    @RequestMapping("/planUsersInsert")
    public String planUsersInsert(AtPlanUsersQuery paramQuery, Model model){
        log.info("==培训用户添加==");
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, new AtPlanUsers());
        /* 查询数据 */
        return "back/train/planUsersInsert";
    }

    /**
     * 培训用户添加提交操作
     * <pre>
     *     需求:
     *     用户列表,选择一个用户,查看用户的计算
     *     点击批量生成的按钮,为用户同步当前机构下面的计划(先删除,再添加)
     * </pre>
     * @return
     */
    @RequestMapping("/planUsersInsertSubmit")
    @ResponseBody
    public String planUsersInsertSubmit(AtPlanUsersQuery paramQuery, Model model){
        log.info("==培训用户添加提交==");
        AtPlanUsers entity = paramQuery.getEntity();
        /* 查询用户信息 */
        AtUsersDescQuery paramUsersDescQuery = new AtUsersDescQuery();
        AtUsersDesc usersDescEntity = paramUsersDescQuery.getEntity();
        usersDescEntity.setId(entity.getUsersId());
        AtUsersDesc usersDesc = this.usersDescService.findOne(paramUsersDescQuery);
        /* 先删除用户下面的所有任务 */
        AtPlanUsersQuery planUsersQuery = new AtPlanUsersQuery();
        AtPlanUsers planUsersEntity = planUsersQuery.getEntity();
        planUsersEntity.setUsersId(entity.getUsersId());
        this.planUsersService.deleteBatch(planUsersQuery);

        boolean dbFlag = false;
        /* 查询当前组织下的计划 */
        AtPlanDescQuery planDescQuery = new AtPlanDescQuery();
        AtPlanDesc planDescEntity = planDescQuery.getEntity();
        planDescEntity.setOrganId(usersDesc.getOrganId());
        planDescEntity.setStatus(BasePojoEnum.STATUS_ENABLE.getCode());
        List<AtPlanDesc> planDescList = this.planDescService.findList(null, planDescQuery);
        for (AtPlanDesc dataTemp : planDescList) {
            AtPlanUsers planUsersObj = new AtPlanUsers();
            planUsersObj.setPlanId(dataTemp.getId());
            planUsersObj.setUsersId(entity.getUsersId());
            planUsersObj.setName(dataTemp.getName());
            dbFlag = this.planUsersService.save(planUsersObj);
            log.info("==添加用户计划:结果:{}==", dbFlag);
        }
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 培训用户打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/planUsersUpdate")
    public String planUsersUpdate(AtPlanUsersQuery paramQuery, Model model){
        log.info("==培训用户更新==");
        /* 根据id查询 */
        AtPlanUsers one = this.planUsersService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "back/train/planUsersUpdate";
        }
        /* 查询数据 */
        return "back/train/planUsersInfo";
    }

    /**
     * 培训用户更新提交操作
     * <pre>
     * 培训用户表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/planUsersUpdateSubmit")
    @ResponseBody
    public String planUsersUpdateSubmit(AtPlanUsersQuery paramQuery, Model model){
        log.info("==培训用户更新提交==");
        AtPlanUsers entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.planUsersService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 培训用户打开添加页面
     * @return
     */
    @RequestMapping("/planUsersBatch")
    @ResponseBody
    public String planUsersBatch(AtPlanUsersQuery paramQuery, Model model){
        log.info("==培训用户批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtPlanUsersQuery paramQueryTemp = new AtPlanUsersQuery();
                        AtPlanUsers entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtPlanUsers dataDbResult = this.planUsersService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.planUsersService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtPlanUsersQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.planUsersService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtPlanUsersQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.planUsersService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.planUsersService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }
}